package com.kobe.Pact.controller;

import com.kobe.Pact.domain.DailyUser;
import com.kobe.Pact.service.DailyService;
import com.kobe.common.annotation.Log;
import com.kobe.common.core.controller.BaseController;
import com.kobe.common.core.domain.AjaxResult;
import com.kobe.common.core.page.TableDataInfo;
import com.kobe.common.enums.BusinessType;
import com.kobe.common.utils.SecurityUtils;
import jdk.nashorn.api.scripting.ScriptUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/kobe/daily")
public class DailyController extends BaseController {
    @Autowired
    private DailyService dailyService;

    /**
     * 查询日常用户列表
     *
     * @param dailyUser 日常用户
     * @return 日常用户列表
     */
    @RequestMapping("/list")
    public TableDataInfo listDailyUser(DailyUser dailyUser) {
        startPage();
        List<DailyUser> list = dailyService.selectDailyUserList(dailyUser);
        return getDataTable(list);
    }

    /**
     * 新增日常用户
     *
     * @param dailyUser 日常用户
     * @return 结果
     */
    @RequestMapping("/add")
    public AjaxResult addDailyUser(@RequestBody DailyUser dailyUser) {
        dailyUser.setCreateTime(new Date());
        dailyUser.setCreateBy(SecurityUtils.getUsername());
        dailyUser.setContractType("1");
        dailyUser.setContractStatus("0");
        int i = dailyService.addDailyUser(dailyUser);
        return AjaxResult.success("新增成功");
    }

    /**
     * 修改日常用户
     *
     * @param dailyUser 日常用户
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('system:contract:edit')")
    @Log(title = "合同", businessType = BusinessType.UPDATE)
    @RequestMapping("/update")
    public AjaxResult edit(@RequestBody DailyUser dailyUser) {
        dailyUser.setUpdateTime(new Date());
        dailyUser.setUpdateBy(SecurityUtils.getUsername());
        int i = dailyService.updateDailyUser(dailyUser);
        return AjaxResult.success("修改成功");
    }
     /**
     * 根据id查询日常用户
     * @param contractId 日常用户id
     * @return 日常用户
     */
     @RequestMapping("/contractId")
    public AjaxResult selectDailyById(@RequestParam("contractId")Long contractId) {
         System.out.println(contractId);
        DailyUser dailyUser = dailyService.selectDailyById(contractId);
        return AjaxResult.success("查询成功", dailyUser);
    }
}
